package day06;

import java.util.Random;

//方法的演示
public class MethodDemo {

    //无参数无返回值
    public static void say() {

        System.out.println("hello");
    }

    //有参数无返回值
    public static void say(String name) {

        System.out.println("我是" + name);
    }

    //有参数无返回值
    public static void say(String name, int age) {

        System.out.println("我是" + name + "，今年" + age + "岁");
    }

    public static void say(int age, String name) {
        System.out.println("今年" + age + "岁了，我是" + name);
    }

    /*public static int say() {

        System.out.println("今年" + age + "岁了，我是" + name);
    }*///编译错误，重载与返回值类型无关

    //有参数有返回值
    public static int sum(int num1, int num2) {
        int num = num1 + num2;
        return num;//返回的是num1和num2的和
        //return num1+num2;//返回的是num1与num2的和
    }

    //生成一个十个数的随机整形数组
    public static int[] generateArray(int len, int max) {
        Random rand = new Random();
        int[] arr = new int[len];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = rand.nextInt(max + 1);
        }
        return arr;
    }


    public static void main(String[] args) {
        /*
        say();//调用方法
        //sayHi(21);//编译错误，参数数据类型需匹配
        //sayHi();//编译错误，有参数必须传参数
        sayHi("Lrx");
        sayHello("Lrx", 21);

        int num = sum(5, 6);//sum(5,6)的值就是return返回的那个数
        System.out.println(num);//模拟对返回结果的后续使用

        int num1 = 3, num2 = 4;
        int num3 = sum(num1, num2);
        System.out.println(num3);

        int[] arr = generateArray(10,1000);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println();

        int[] arr1 = generateArray(4,500);
        Arrays.sort(arr);
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
       */

        //
        say();//自动绑定无参say
        say("Lrx");//自动绑定String参的say
        say("Lrx", 21);//自动绑定String+int的san

    }


}
